#include <iostream>
#include <cmath>
#include <cassert>

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>

#include <set>

#include "matrix.h"
#include "matrix_util.h"
#include "primitive.h"
#include "mesh.h"
#include "aabbtree.h"


#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>



#include "intersect_2d.h"
#include "intersect_3d.h"

//typedef double Value;


#ifndef CORE_LEVEL
#   define CORE_LEVEL 3
#endif

#define CORE_NO_AUTOMATIC_NAMESPACE
#define GLFLOAT(VAL) \
        VAL.doubleValue()

#include "CORE/CORE.h" 

typedef CORE::Expr Value ;


typedef typename MeshPrimitive<Value>::PointType     PointType  ;
typedef typename MeshPrimitive<Value>::VectorType    VectorType ;
typedef typename MeshPrimitive<Value>::FaceType      FaceType   ;
typedef typename MeshPrimitive<Value>::VertexType    VertexType ;
typedef Mesh <MeshPrimitive<Value> >                 MeshType ;

typedef AABBTreePoly <Value>                         AABBTreePolyType;
typedef AABBTreePolyBuilder <Value>                  AABBTreePolyBuilderType  ;
typedef AABBTreePolygon <Value>                      AABBTreePolygonType ;
typedef AABBTreeNode <Value> AABBTreeNodeType ;
typedef Box<Value> BoxType;
typedef Segment<Value> SegmentType;
typedef Polygon<Value> PolygonType;


#include "ut_predicate.h"
#include "ut_intersect.h"
#include "ut_intersect_2d.h"




int main (int argc, char* argv[])
{
    // informs test-listener about testresults
    CPPUNIT_NS :: TestResult testresult;

    // register listener for collecting the test-results
    CPPUNIT_NS :: TestResultCollector collectedresults;
    testresult.addListener (&collectedresults);

    // register listener for per-test progress output
    CPPUNIT_NS :: BriefTestProgressListener progress;
    testresult.addListener (&progress);

    // insert test-suite at test-runner by registry
    CPPUNIT_NS :: TestRunner testrunner;
    testrunner.addTest (CPPUNIT_NS :: TestFactoryRegistry :: getRegistry().makeTest ());
    testrunner.run (testresult);

    // output results in compiler-format
    CPPUNIT_NS :: CompilerOutputter compileroutputter (&collectedresults, std::cerr);
    compileroutputter.write ();

    // return 0 if tests were successful
    return collectedresults.wasSuccessful () ? 0 : 1;
}

